package servlet;

import model.Page;
import service.OrderService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/order_list")
public class AdminOrderListServlet extends HttpServlet {
    private OrderService oService = new OrderService();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int status = 0; // 默认显示全部订单
        if (request.getParameter("status") != null) {
            status = Integer.parseInt(request.getParameter("status"));
        }

        int pageNo = 1; // 默认第一页
        if (request.getParameter("pageNo") != null) {
            pageNo = Integer.parseInt(request.getParameter("pageNo"));
        }

        Page page = oService.getOrderPage(status, pageNo);
        System.out.println("Page Data: " + page.getList()); // 打印数据
        request.setAttribute("page", page); // 将数据传递到 JSP
        request.getRequestDispatcher("/admin/order_list.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}